package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.CustomerPhoto;
import com.ruoyi.system.mapper.ComboMapper;
import com.ruoyi.system.mapper.CustomerMapper;
import com.ruoyi.system.mapper.PhotographerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BookingMapper;
import com.ruoyi.system.domain.Booking;
import com.ruoyi.system.service.IBookingService;

/**
 * 预约信息Service业务层处理
 * 
 * @author Eugene
 * @date 2023-04-14
 */
@Service
public class BookingServiceImpl implements IBookingService 
{
    @Autowired
    private BookingMapper bookingMapper;

    @Autowired
    private ComboMapper comboMapper;

    @Autowired
    private CustomerMapper customerMapper;

    @Autowired
    private PhotographerMapper photographerMapper;
    /**
     * 查询预约信息
     * 
     * @param id 预约信息主键
     * @return 预约信息
     */
    @Override
    public Booking selectBookingById(Long id)
    {
        return bookingMapper.selectBookingById(id);
    }

    /**
     * 查询预约信息列表
     * 
     * @param booking 预约信息
     * @return 预约信息
     */
    @Override
    public List<Booking> selectBookingList(Booking booking)
    {
        List<Booking> list = bookingMapper.selectBookingList(booking);

        for (Booking booking2 : list) {
            //如果没有查询到combo_name，就设置为null
            if (comboMapper.selectComboById(booking2.getComboId()) == null) {
                booking2.setComboName(null);
            }else {
                booking2.setComboName(comboMapper.selectComboById(booking2.getComboId()).getComboName());
            }
        }

        //按照客照关系表中的customer_id查询customer表中的customer_name
        for (Booking booking2 : list) {
            //如果没有查询到customer_name，就设置为null
            if (customerMapper.selectCustomerById(booking2.getCustomerId()) == null) {
                booking2.setCustomerName(null);
            }else {
                booking2.setCustomerName(customerMapper.selectCustomerById(booking2.getCustomerId()).getName());
            }
        }

        //按照客照关系表中的photographer_id查询photographer表中的photographer_name
        for (Booking booking2 : list) {
            //如果没有查询到photographer_name，就设置为null
            if (photographerMapper.selectPhotographerById(booking2.getPhotographerId()) == null) {
                booking2.setPhotographerName(null);
            }else {
                booking2.setPhotographerName(photographerMapper.selectPhotographerById(booking2.getPhotographerId()).getName());
            }
        }
        return list;
    }

    /**
     * 新增预约信息
     * 
     * @param booking 预约信息
     * @return 结果
     */
    @Override
    public int insertBooking(Booking booking)
    {
        booking.setCreateTime(DateUtils.getNowDate());
        return bookingMapper.insertBooking(booking);
    }

    /**
     * 修改预约信息
     * 
     * @param booking 预约信息
     * @return 结果
     */
    @Override
    public int updateBooking(Booking booking)
    {
        booking.setUpdateTime(DateUtils.getNowDate());
        return bookingMapper.updateBooking(booking);
    }

    /**
     * 批量删除预约信息
     * 
     * @param ids 需要删除的预约信息主键
     * @return 结果
     */
    @Override
    public int deleteBookingByIds(Long[] ids)
    {
        return bookingMapper.deleteBookingByIds(ids);
    }

    /**
     * 删除预约信息信息
     * 
     * @param id 预约信息主键
     * @return 结果
     */
    @Override
    public int deleteBookingById(Long id)
    {
        return bookingMapper.deleteBookingById(id);
    }
}
